package com.thunisoft.intranet.order.action.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import antlr.debug.TraceAdapter;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.thunisoft.intranet.domain.TOrder;
import com.thunisoft.intranet.order.action.IOrderAction;
import com.thunisoft.intranet.order.service.IOrderService;

public class OrderActionImpl extends ActionSupport implements IOrderAction {
	
	@Autowired
	private IOrderService orderService;
	
	private String orderName;
	private BigDecimal orderPrice;
	private TOrder order;
	
	public void saveOrderInfo() {
		ActionContext context = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest)context.
									get(ServletActionContext.HTTP_REQUEST);
		orderName = request.getParameter("order.CName");
		String price = request.getParameter("order.CPrice");
		orderPrice = new BigDecimal(price);
//		orderPrice = orderPrice.setScale(2);
		TOrder newOrder = new TOrder();
		newOrder.setCName(orderName);
		newOrder.setCPrice(orderPrice);
		orderService.saveOrderInfo(newOrder);		
	}

	@Override
	public String getOrderList() {
		ActionContext context = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
//		HttpServletResponse response = (HttpServletResponse)context.get(ServletActionContext.HTTP_RESPONSE);
		List<TOrder> orderList = orderService.getOrderList();
		request.setAttribute("orderlist", orderList);
		return "orderList";
	}

	public TOrder getOrder() {
		return order;
	}

	public void setOrder(TOrder order) {
		this.order = order;
	}
	
}
